package com.beordie.service.impl;

import com.beordie.dao.IDriverDao;
import com.beordie.dao.impl.DriverDaoImpl;
import com.beordie.model.Driver;
import com.beordie.model.FormatDriver;
import com.beordie.service.IDriverService;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname DriverServiceImpl
 * @Description TODO
 * @Date 2021/7/13 19:52
 * @Created 30500
 */
public class DriverServiceImpl implements IDriverService {
    IDriverDao driverDao = new DriverDaoImpl();

    @Override
    public List<FormatDriver> getAllDrivers() {
        List<Driver> list = driverDao.getAllDrivers();
        List<FormatDriver> drivers = new ArrayList<>();
        if (list != null && list.size() > 0)
            for (Driver driver : list)
                drivers.add(new FormatDriver(driver));
        else
            return null;
        return drivers;
    }

    @Override
    public List<FormatDriver> getAllByLimit(boolean isLimit, int start, int size) {
        List<Driver> list = driverDao.getAllByLimit(isLimit, start, size);
        List<FormatDriver> drivers = new ArrayList<>();
        if (list != null && list.size() > 0)
            for (Driver driver : list)
                drivers.add(new FormatDriver(driver));
        else
            return null;
        return drivers;
    }

    @Override
    public int insert(Driver driver) {
        return driverDao.insert(driver);
    }

    @Override
    public int deleteById(int id) {
        return driverDao.deleteById(id);
    }

    @Override
    public int updateById(Driver driver, int id) {
        return driverDao.updateById(driver, id);
    }

    @Override
    public int getCount() {
        return driverDao.getCount();
    }

    @Override
    public FormatDriver findByNumName(String condition) {
        Driver driver = driverDao.findByNumName(condition);
        if (driver != null)
            return new FormatDriver(driver);
        return null;
    }
}
